#include <DataConverter>
#include <iostream>
#include <random>

using namespace std;

int main() {
  QByteArray header;
  header.append(0x55);
  header.append(0xAA);

  {
    cout << "simple write and read." << endl;
    DataConverter con(header, 10);
    default_random_engine re;
    uniform_int_distribution<> id;
    uniform_int_distribution<short> cd;
    int a = id(re), b = id(re);
    char c = static_cast<char>(cd(re)), e = cd(re);

    cout << "a: " << a << "\tb: " << b << "\tc: " << c << "\te: " << e << endl;

    con.beginPush();
    con.push(a);
    con.push(b);
    con.push(c);
    con.push(e);
    con.endPush();

    a = id(re), b = id(re);
    c = cd(re), e = cd(re);

    while (con.has()) {
      a = con.pop<int>();
      b = con.pop<int>();
      c = con.pop<char>();
      e = con.pop<char>();
      cout << "a: " << a << "\tb: " << b << "\tc: " << c << "\te: " << e
           << endl;
    }

    {
      cout << "write and read, if data type size mismathes number of bytes."
           << endl;
      DataConverter con(header, 6);

      unsigned int a = 234023;
      unsigned int b = 859388;

      cout << "write: a: " << a << "\tb: " << b << endl;
      con.beginPush();
      con.push(a, 3);
      con.push(b, 3);
      con.endPush();

      a = 12309, b = 344099;
      while (con.has()) {
        a = con.pop<unsigned int>(3);
        b = con.pop<unsigned int>(3);
        cout << "read: a: " << a << "\tb: " << b << endl;
      }
    }
  }

  return 0;
}
